package com.qs.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * 时期查询选项
 */
public enum PeriodOption {
	ALL(1, "全部"), 
	CUR_YEAR(2, "本年"), 
	FIRSTHALF_YEAR(3, "上半年"), 
	LASTHALF_YEAR(4, "下半年"), 
	CUR_QUARTER(5, "本季度"), 
	PREV_MONTH(6, "上月"), 
	CUR_MONTH(7, "本月"), 
	PREV_WEEK(8, "上周"), 
	CUR_WEEK(9, "本周"), 
	TODAY(10, "当日"), 
	RECENT_THREE_DAYS(11, "最近三天");
//	CUSTOM(12, "自定义");

	private int value;
	private String title;

	PeriodOption(int value, String title) {
		this.value = value;
		this.title = title;
	}

	/**
	 * 获取枚举值
	 * 
	 * @return 返回枚举值
	 */
	public int value() {
		return this.value;
	}

	/**
	 * 获取枚举标题
	 * 
	 * @return 返回枚举的标题
	 */
	public String title() {
		return this.title;
	}

	private static Map<String, PeriodOption> titlefinder;
	static {
		titlefinder = new HashMap<String, PeriodOption>();
		for (PeriodOption item : PeriodOption.values())
			titlefinder.put(item.title(), item);

	}

	private static Map<Integer, PeriodOption> valuefinder;
	static {
		valuefinder = new HashMap<Integer, PeriodOption>();
		for (PeriodOption item : PeriodOption.values())
			valuefinder.put(new Integer(item.value()), item);

	}

	/**
	 * 按照枚举值查找枚举
	 * 
	 * @param value
	 *            数据类型值对象
	 * @return 返回枚举值对象
	 */
	public static PeriodOption valueOf(int type) {
		return valuefinder.get(new Integer(type));
	}

	/**
	 * 按照枚举标题查找枚举值
	 * 
	 * @param value
	 *            数据类型值对象
	 * @return 返回枚举值对象
	 */
	public static PeriodOption titleOf(String title) {
		return titlefinder.get(title);
	}

	public static PeriodOption[] getMembers() {
		return new PeriodOption[] { ALL, CUR_YEAR, FIRSTHALF_YEAR, LASTHALF_YEAR,
				CUR_QUARTER, PREV_MONTH, CUR_MONTH, PREV_WEEK, CUR_WEEK, TODAY,
				RECENT_THREE_DAYS};
	}
}
